AND operator
Skip to main content Microsoft Technologies Documentation Resources .NET .NET APIs.NET Core.NET FrameworkASP.NETXamarinAzure And Operator (Visual Basic) 7/29/2017 2 min to read Contributors Performs a logical conjunction on two Boolean expressions, or a bitwise conjunction on two numeric expressions. Syntax Copy result = expression1 And expression2 Parts result Required. Any Boolean or numeric expression. For Boolean comparison, result is the logical conjunction of two Boolean values. For bitwise operations, result is a numeric value representing the bitwise conjunction of two numeric bit patterns. expression1 Required. Any Boolean or numeric expression. expression2 Required. Any Boolean or numeric expression. Remarks For Boolean comparison, result is True if and only if both expression1 and expression2 evaluate to True. The following table illustrates how result is determined. If expression1 is And expression2 is The value of result is True True True True False False False True False False False False Note In a Boolean comparison, the And operator always evaluates both expressions, which could include making procedure calls. The AndAlso Operator performs short-circuiting, which means that if expression1 is False, then expression2 is not evaluated. When applied to numeric values, the And operator performs a bitwise comparison of identically positioned bits in two numeric expressions and sets the corresponding bit in result according to the following table. If bit in expression1 is And bit in expression2 is The bit in result is 1 1 1 1 0 0 0 1 0 0 0 0 Note Since the logical and bitwise operators have a lower precedence than other arithmetic and relational operators, any bitwise operations should be enclosed in parentheses to ensure accurate results. Data Types If the operands consist of one Boolean expression and one numeric expression, Visual Basic converts the Boolean expression to a numeric value (–1 for True and 0 for False) and performs a bitwise operation. For a Boolean comparison, the data type of the result is Boolean. For a bitwise comparison, the result data type is a numeric type appropriate for the data types of expression1 and expression2. See the "Relational and Bitwise Comparisons" table in Data Types of Operator Results. Note The And operator can be overloaded, which means that a class or structure can redefine its behavior when an operand has the type of that class or structure. If your code uses this operator on such a class or structure, be sure you understand its redefined behavior. For more information, see Operator Procedures. Example The following example uses the And operator to perform a logical conjunction on two expressions. The result is a Boolean value that represents whether both of the expressions are True. VB Copy Dim a As Integer = 10 Dim b As Integer = 8 Dim c As Integer = 6 Dim firstCheck, secondCheck As Boolean firstCheck = a > b And b > c secondCheck = b > a And b > c The preceding example produces results of True and False, respectively. Example The following example uses the And operator to perform logical conjunction on the individual bits of two numeric expressions. The bit in the result pattern is set if the corresponding bits in the operands are both set to 1. VB Copy Dim a As Integer = 10 Dim b As Integer = 8 Dim c As Integer = 6 Dim firstPattern, secondPattern, thirdPattern As Integer firstPattern = (a And b) secondPattern = (a And c) thirdPattern = (b And c) The preceding example produces results of 8, 2, and 0, respectively. See Also Logical/Bitwise Operators (Visual Basic) Operator Precedence in Visual Basic Operators Listed by Functionality AndAlso Operator Logical and Bitwise Operators in Visual Basic 0 Comments Sign in0 people listening + Follow Post comment as... Comments Edit Share Theme In this article Syntax Parts Remarks Data Types Example Example See Also Docs.NETVisual Basic GuideLanguage reference Welcome .NET Guide .NET Core Guide .NET Framework Guide C# Guide F# Guide Visual Basic Guide Get Started Developing Applications Programming Concepts Program Structure and Code Conventions Language Features COM Interop Language Reference Typographic and Code Conventions Visual Basic Runtime Library Members Keywords Attributes Constants and Enumerations Data Type Summary Directives Functions Modifiers Modules Nothing Objects Operators Operator Precedence Operators Listed by Functionality & Operator &= Operator * Operator *= Operator + Operator += Operator = Operator - Operator -= Operator << Operator <<= Operator >> Operator >>= Operator / Operator /= Operator \ Operator \= Operator ^ Operator ^= Operator AddressOf Operator And Operator AndAlso Operator Await Operator Function Expression GetType Operator GetXmlNamespace Operator If Operator Is Operator IsFalse Operator IsNot Operator IsTrue Operator Like Operator Mod Operator Not Operator Or Operator OrElse Operator Sub Expression TypeOf Operator Xor Operator Data Types of Operator Results DirectCast Operator TryCast Operator New Operator Arithmetic Operators Assignment Operators Bit Shift Operators Comparison Operators Concatenation Operators Logical-Bitwise Operators Miscellaneous Operators Properties Queries Statements XML Comment Tags XML Axis Properties XML Literals Error Messages Reference Sample Applications Walkthroughs Samples and Tutorials Download PDF Is this page helpful? YES NO English (United States) Blog Privacy & Cookies Terms of Use Feedback Trademarks Category:Boolean